package com.testDemo.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.testDemo.enrty.AopTestException;
import com.testDemo.enrty.TestDemoResult;
import com.testDemo.service.RequestService;

@Controller
@RequestMapping("/client")
public class ClientController {

    @Resource
    private RequestService req;

    /**
     * 发送请求到测试环境,发起测试
     * @param url
     * @param appkey
     * @param bizkey
     * @param method
     * @param msg
     * @return
     */
    @ResponseBody
    @RequestMapping("/doClient.do")
    public TestDemoResult doClient(String url, String appkey, String bizkey, String method, String msg) {
        TestDemoResult result = null;
        try {
            result = req.doClient(url, appkey, bizkey, method, msg);
        }
        catch (AopTestException e) {
            result = new TestDemoResult(e.getCode(), e.getDetail(), "");
        }
        catch (Exception e) {
            e.printStackTrace();
            result = new TestDemoResult(TestDemoResult.ERROR_CODE, e.getMessage(), "");
        }
        return result;
    }

}
